// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { game } from "../../../../script/game/control/game";
import { ItemBase } from "../../../../script/game/control/Item/ItemBase";
import { itemType } from "../../../../script/game/gameType";
import { ccs } from "../../../../script/util/services";
import { WinBase } from "../../../../script/wins/WinBase";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends WinBase {

    @property(cc.Label)
    label: cc.Label = null;

    item: itemType;
    count: number = 1;
    cost: number = 0;
    start () {
        this.item = ccs.dataMgr.getItemsById(this._args.id);
        this.nodes.itemName.getComponent(cc.Label).string = this.item.name;
        this.nodes.desc.getComponent(cc.Label).string = this.item.desc;
        let effStr = '效果：'
        //效果展示
        for(let key in this.item.effect) {
            effStr += ccs.dataMgr.getAttributeNameById(key).name + ":" + this.item.effect[key].point + ",";
        }
        this.nodes.effect.getComponent(cc.Label).string = effStr;
        this.touchEndEventScale(this.nodes.ensure, () => {
            this.useItem();
        })
    }
    useItem() {
        //
        game.playerMgr.useItem(new ItemBase(this.item, 1));
        cc.log(game.playerMgr.bag.itemsBag);
    }
    del() {
        //丢弃
        game.playerMgr.bag.itemsBag.delItem(this.item.id, 1);
        this._close();

    }
}
